//stack.h
#ifndef STACK_H_
#define STACK_H_

typedef unsigned long Item;     //项数

class Stack
{
    private:
        enum {MAX = 10};    //最大项数
        Item items[MAX];    //项数的数组
        int top;            //栈顶元素
    public:
        Stack();
        bool isempty() const;   //判断栈是否为空
        bool isfull() const;    //判断栈是否为满
        bool pop (Item &item);  //清除栈的顶
        bool push(const Item & item);   //推入到栈顶上
};

#endif

/*接口部分*/
// #include "stack.h"
Stack::Stack() { top = 0; } //构造函数，

bool Stack::isempty() const { return top == 0; } //判空

bool Stack::isfull() const {return top == MAX; }

bool Stack::push (const Item &item)  //
{
    if (top < MAX)
    {
        items[top++] = item;
        return true;
    }
    else
        return false;
}

bool Stack::pop(Item &item)     //清除栈的项
{
    if (top > 0)
    {
        item = items[--top];
        return true;
    }
    else
        return false;
}

/**/
#include <iostream>
#include <cctype>
// #include "stack.h"
int main()
{
    using namespace std;
    Stack st;
    char ch;
    unsigned long po;
    cout << "请输入A来添加一个购买方案\n" << "输入P来进行一个PO，输入Q来退出\n";

    while (cin >> ch && toupper(ch) != 'Q')
    {
        continue;
    if (!isalpha(ch))
    {
        cout << '\a';
        continue;
    }
    switch (ch)
    {
        case 'A':
        case 'a': cout << "输入一个PO数字来添加：";
        cin >> po;
        if (st.isfull())
            cout << "栈已经满了";
        else
            st.push(po);
        break;

        case 'p':
        case 'P': if (st.isempty())
                    cout << "栈已经空了";
                  else
                {
                    st.pop(po);
                    cout << "PO #" << po << "\n";
                }
                break;
    }
    cout << "请输入A来添加一个购物方案,\n" << "输入p来进行一个PO，输入Q来退出\n";
    }
    cout << "再见\n";
    return 0;
}